<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :formType="type" @formChange="formChangeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <!-- <FormPanel ref="formPanel1" :list="formList1" :formType="type" @formChange="formChangeHandle1" :isSubmitBtn="false" :collapse="false" labelWidth="110" /> -->
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button @click="closeDrawer">返 回</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { queryRetailOrderById } from '@/api/omSale/ActualSales/RetailOrders';
import { getEmployees, queryVinForOrder, queryPotentialCustomer } from '@/api/dealerSale/SalesSanagement/RetailOrderReview';

export default {
  mixins: [dictionary],

  props: {
    type: {
      type: String,
      default: 'show'
    },
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  // components: {
  //   SearchCstmr,
  //   SearchVin
  // },
  data() {
    this.saveData = null;
    // this.saveData1 = null;
    return {
      formList: this.createdFrom(),
      // formList1: this.createdFrom1(),
      isShowCstmr: false,
      isShowVin: false,
      formData: {},
      editData: {},
      detailData: null,
      cstmrData: null,
      vinData: null
    };
  },
  mounted() {
    this.init();
    // this.queryEmployees();
  },
  methods: {
    init() {
      if (this.type != 'add') {
        this.getInfoById();
      }
      if (this.type == 'show') {
        this.formList.map(x => {
          if (x.rules) {
            x.rules[0].required = false;
          }
        });
      }
    },
    // 查询销售顾问
    async queryEmployees() {
      const res = await getEmployees();
      if (res.resultCode == 200) {
        res.data.map(x => {
          this.formList.find(item => item.fieldName == 'salesManId').itemList.push({ text: x.userName, value: x.userId });
        });
      }
    },
    // 根据ID查详细
    async getInfoById() {
      const res = await queryRetailOrderById(this.rowData.soNoId);
      if (res.resultCode == 200) {
        this.detailData = res.data;
        for (let i in res.data) {
            this.formList.map(x => {
            if (x.fieldName == i) {
              x.initialValue = res.data[i];
            }
          });
        }

        this.formList.map(x => {
          // 潜客信息替换页面信息vsCustomerDTO 客户编号、客户姓名、手机号、证件类型、证件号、联系地址
          if (x.fieldName == 'customerNo' || x.fieldName == 'customerName' || x.fieldName == 'customerPhone' || x.fieldName == 'cardType' || x.fieldName == 'cardNo' || x.fieldName == 'linkAddress') {
            let data = res.data.vsCustomerDTO;
            if (x.fieldName == 'customerPhone') {
              x.initialValue = data['mobile'];
            } else {
              x.initialValue = data[x.fieldName];
            }
          } else {
            x.initialValue = res.data[x.fieldName];
          }
        });
        // this.formList1.map(x => {
        //   if (x.fieldName == 'salesQuatation' || x.fieldName == 'checkDesc') {
        //     x.initialValue = res.data[x.fieldName];
        //   } else if (x.fieldName == 'discountAmount') {
        //     let result = 0;
        //     result = parseFloat(res.data.orderVinShowDto.basicPrice) - parseFloat(res.data.salesQuatation);
        //     x.initialValue = result || 0;
        //   } else {
        //     let data = res.data.orderVinShowDto;
        //     x.initialValue = data[x.fieldName];
        //   }
        // });
      }
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    // formChangeHandle1(val) {
    //   this.saveData1 = val;
    // },
    closeDrawer() {
      this.$emit('close', false, '');
    },
    // 查询潜客
    cstmrNoHandle() {
      this.isShowCstmr = true;
    },
    closeDialog(val, data) {
      this.isShowCstmr = val;
      this.cstmrData = data[0];
      this.setFormData(data[0]);
      console.log(data, '---关闭潜客---');
    },
    closeDialog1(val, data) {
      this.isShowVin = val;
      this.vinData = data[0];
      this.setFormData(data[0]);
      console.log(data, '---关闭VIN---');
    },
    setFormData(data) {
      for (let key in data) {
        this.formList.map(x => {
          if (x.fieldName == key) {
            x.initialValue = data[x.fieldName];
          }
        });
      }
    },
    // 查询VIN
    vinHandle() {
      this.isShowVin = true;
    },
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '客户信息'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '',
          disabled: true
          // rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
        {
          type: 'INPUT',
          label: '客户手机号',
          fieldName: 'customerTel',
          placeholder: '',
          disabled: true
          // rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        },
         {
          type: 'BREAK_SPACE',
          label: '订单基础信息'
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'dealerCode',
          placeholder: '自动生成',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '经销商',
          fieldName: 'dealerName',
          placeholder: '',
          disabled: true
        }, {
          type: 'INPUT',
          label: '零售订单号',
          fieldName: 'soNo',
          placeholder: '',
          disabled: true
        },
        {
          type: 'DATE',
          label: '零售订单创建时间',
          fieldName: 'sheetCreateDate',
          dateType: 'exactdate',
          format: 'yyyy-MM-dd HH:mm:ss',
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '零售订单状态',
          fieldName: 'soStatus',
          placeholder: '',
          itemList: this.createDlrDictList('2702')
        },
        // {
        //   type: 'INPUT',
        //   label: '开票人',
        //   fieldName: 'drawerName',
        //   placeholder: '请输入',
        //   disabled: true
        // },


        {
          type: 'DATE',
          label: '实际交车时间',
          fieldName: 'handoverTime',
          dateType: 'exactdate',
          format: 'yyyy-MM-dd HH:mm:ss',
          placeholder: ''
        },
        // {
        //   type: 'SELECT',
        //   label: '开票状态',
        //   fieldName: 'cardType',
        //   placeholder: '',
        //   itemList: this.createDlrDictList('1508')
        // },
        // {
        //   type: 'DATE',
        //   label: '开票时间',
        //   fieldName: 'invoiceDate',
        //   dateType: 'exactdate',
        //   format: 'yyyy-MM-dd HH:mm:ss',
        //   placeholder: ''
        // },
        {
          type: 'INPUT',
          label: '销售顾问',
          fieldName: 'consultantName',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'DATE',
          label: '订单取消时间',
          fieldName: 'cancelTime',
          dateType: 'exactdate',
          format: 'yyyy-MM-dd HH:mm:ss',
          placeholder: ''
        },
          {
          type: 'BREAK_SPACE',
          label: '车辆信息'
        },
        {
          type: 'SELECT',
          label: '配车状态',
          fieldName: 'dispatchedStatus',
          placeholder: '',
          itemList: this.createDlrDictList('2653')
        },
        {
          type: 'DATE',
          label: '配车时间',
          fieldName: 'dispatchedData',
          dateType: 'exactdate',
          format: 'yyyy-MM-dd HH:mm:ss',
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '车辆是否出库',
          fieldName: 'isDelivery',
          placeholder: '',
          itemList: this.createDlrDictList('1004')
        },
        {
          type: 'INPUT',
          label: '物料编码',
          fieldName: 'productCode',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '物料描述',
          fieldName: 'productName',
          placeholder: '请输入',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'seriesName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配置',
          fieldName: 'configName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '选装',
          fieldName: 'optionName',
          placeholder: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimColorName',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '外饰',
          fieldName: 'colorName',
          placeholder: '请选择',
          disabled: true
        },
        {
          type: 'INPUT',
          label: 'VIN号',
          fieldName: 'vin',
          placeholder: '',
          disabled: true
        },

        // {
        //   type: 'SELECT',
        //   label: '证件类型',
        //   fieldName: 'cardType',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('1508'),
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }]
        // },
        // {
        //   type: 'INPUT',
        //   label: '证件号',
        //   fieldName: 'cardNo',
        //   placeholder: '请输入',
        //   rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        // },
        // {
        //   type: 'INPUT',
        //   label: '联系地址',
        //   fieldName: 'linkAddress',
        //   placeholder: '请输入',
        //   selfCols: 2,
        //   rules: [{ required: true, message: '请输入', trigger: 'blur' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '购车用途',
        //   fieldName: 'buyPurpose',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('1511')
        // },
        // {
        //   type: 'INPUT',
        //   label: '开单人',
        //   fieldName: 'sheetManName',
        //   placeholder: '',
        //   disabled: true
        // },
        // {
        //   type: 'DATE',
        //   label: '签约日期',
        //   fieldName: 'signDate',
        //   dateType: 'exactdate',
        //   placeholder: '请选择'
        // },


        // {
        //   type: 'SELECT',
        //   label: '支付方式',
        //   fieldName: 'payType',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('6015'),
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }]
        // },

        // {
        //   type: 'INPUT',
        //   label: '定金金额',
        //   fieldName: 'depositAmount',
        //   placeholder: '请输入'
        // },
        // {
        //   type: 'DATE',
        //   label: '定金日期',
        //   fieldName: 'depositDate',
        //   dateType: 'exactdate',
        //   placeholder: '请选择'
        // },
        // {
        //   type: 'SELECT',
        //   label: '大客户订单',
        //   fieldName: 'isMajor',
        //   placeholder: '请选择',
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }],
        //   itemList: this.createDictList('1004')
        // },
        // {
        //   type: 'SELECT',
        //   label: '特殊订单',
        //   fieldName: 'isSpecial',
        //   placeholder: '请选择',
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }],
        //   itemList: this.createDictList('1004')
        // },
        // {
        //   type: 'CHECKBOX',
        //   label: '大客户订单',
        //   fieldName: 'isMajor',
        //   options: { trueValue: 10041001, falseValue: 10041002 }

        //   // rules: [{ required: true, message: '请选择', trigger: 'change' }]
        // },

        // {
        //   type: 'CHECKBOX',
        //   label: '特殊订单',
        //   fieldName: 'isSpecial',
        //   options: { trueValue: 10041001, falseValue: 10041002 }

        //   // rules: [{ required: true, message: '请选择', trigger: 'change' }]
        // },
        // {
        //   type: 'SELECT',
        //   label: '订单类型',
        //   fieldName: 'orderType',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('6026'),
        //   rules: [{ required: true, message: '请选择', trigger: 'change' }]
        // },
        // {
        //   type: 'TEXT_AREA',
        //   label: '备注',
        //   fieldName: 'remark',
        //   placeholder: '请输入',
        //   selfCols: 3
        // }
      ];
    }
    // ,createdFrom1() {
    //   return [
    //     {
    //       type: 'BREAK_SPACE',
    //       label: '车辆信息'
    //     },

    //     {
    //       type: 'INPUT',
    //       label: '发动机号',
    //       fieldName: 'engineNo',
    //       placeholder: '请输入',
    //       disabled: true
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '电机号',
    //       fieldName: 'motorCode',
    //       placeholder: '请输入',
    //       disabled: true
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '电池号',
    //       fieldName: 'batteryNo',
    //       placeholder: '请输入',
    //       disabled: true
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '合格证号',
    //       fieldName: 'certificateNo',
    //       placeholder: '请输入',
    //       disabled: true
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '品牌',
    //       fieldName: 'brandName',
    //       placeholder: '请选择',
    //       disabled: true
    //     },


    //     {
    //       type: 'INPUT',
    //       label: '销售指导价',
    //       fieldName: 'basicPrice',
    //       placeholder: '请输入',
    //       disabled: true
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '销售报价',
    //       fieldName: 'salesQuatation',
    //       placeholder: '请输入',
    //       onInput: val => {
    //         console.log(val, '---销售报价---');
    //         let result = 0;
    //         let basicPrice = this.formList1.find(x => x.fieldName === 'basicPrice').initialValue || 0;
    //         result = parseFloat(basicPrice) - parseFloat(val);
    //         this.formList1.find(x => x.fieldName === 'discountAmount').initialValue = result || 0;
    //       }
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '折让金额',
    //       fieldName: 'discountAmount',
    //       placeholder: '请输入',
    //       initialValue: '',
    //       disabled: true
    //     },

    //     {
    //       type: 'INPUT',
    //       label: '出库时间',
    //       fieldName: 'stockOutData',
    //       placeholder: '请输入',
    //       disabled: true
    //     },
    //     {
    //       type: 'INPUT',
    //       label: '交车里程',
    //       fieldName: 'deliveryMileage',
    //       placeholder: '请输入',
    //       disabled: true
    //     }
    //   ];
    // }
  }
};
</script>
